#include <vector>
using namespace std;
/*
 * @lc app=leetcode.cn id=238 lang=cpp
 *
 * [238] 除自身以外数组的乘积
 */

// @lc code=start
class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        int front = 1, back = 1, sz = nums.size();
        vector<int> ans(sz, 1);
        for (int i = 1; i < sz; i++) {
            front = front * nums[i - 1];
            ans[i] = front;
        }
        for (int i = sz - 2; i >= 0; i--) {
            back = back * nums[i + 1];
            ans[i] *= back;
        }
        return ans;
    }
};
// @lc code=end

